package b2.widget.friend
{
	import b2.net.*;
	import b2.player.*;
	import b2.player.dataModel.*;
	import b2.widget.*;
	import b2.widget.sendMail.*;
	import b2.widget.tank.*;
	import b2.widget.warehouse.*;
	import b2.util.*;
	
	import com.bit101.components.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.Mouse;
	
	public class FriendItemMessage extends Sprite
	{
		private var friendItem:FriendItem;
		
		public function FriendItemMessage(friendItem:FriendItem)
		{
			super();
			this.friendItem = friendItem;
			var roundRec:RoundRec = new RoundRec(90, 65, 0.8, BFont.roundRecColor);
			addChild(roundRec);
			//显示信息
			var showText:TextField = new TextField();
			showText.selectable = false;
        	showText.autoSize = TextFieldAutoSize.LEFT;
			showText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x0000FF, true, null, true);
			showText.text = "显示信息";
			showText.x = 15;
			showText.y = 10;
			showText.addEventListener(MouseEvent.MOUSE_OVER, onTextMouseOver);
			showText.addEventListener(MouseEvent.MOUSE_OUT, onTextMouseOut);
			showText.addEventListener(MouseEvent.CLICK, showTankInfo);
			addChild(showText);
			//显示信息
			var sendText:TextField = new TextField();
			sendText.selectable = false;
        	sendText.autoSize = TextFieldAutoSize.LEFT;
			sendText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x0000FF, true, null, true);
			sendText.text = "发送邮件";
			sendText.x = 15;
			sendText.y = 30;
			sendText.addEventListener(MouseEvent.MOUSE_OVER, onTextMouseOver);
			sendText.addEventListener(MouseEvent.MOUSE_OUT, onTextMouseOut);
			sendText.addEventListener(MouseEvent.CLICK, sendMail);
			addChild(sendText);
		}
		
		private function onTextMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
		}
		
		private function onTextMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
		}
		
		//显示坦克信息
		private function showTankInfo(event:MouseEvent):void
		{
			ServerHelper.getInstance().getPlayerInfo(friendItem.playerId);
			ServerHelper.getInstance().addEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
		}
		
		private function onShowTankInfoComplete(event:ServerEvent):void
		{
			ServerHelper.getInstance().removeEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
			var playerInfo:PlayerInfo = PlayerInfoManager.getInstance().players[friendItem.playerId];
			TankDialog.getInstance().fresh(playerInfo.campTankId);
			WidgetManager.getInstance().popOut([TankDialog.getInstance()], true, true);
		}
		
		private function sendMail(event:MouseEvent):void
		{
			var sendMailTab:SendMailTab = SendMailTab.getInstance();
			if (sendMailTab.mail == null)
			{
				sendMailTab.mail = new Mail(PlayerInfoManager.getInstance().myUserId, friendItem.playerId);
			}
			else 
			{
				sendMailTab.mail.setToId(friendItem.playerId);
			}
			sendMailTab.x = 40;
			sendMailTab.y = 100;
			var warehouse:Warehouse = Warehouse.getInstance();
			warehouse.refresh();
			warehouse.x = 386;
			warehouse.y = 100; 
			WidgetManager.getInstance().popOut([warehouse, sendMailTab], true);	
		}
	}
}